/**
 * 
 */
package com.goodedeeds.webapp.controller;

import net.sourceforge.stripes.action.*;

import java.util.Date;
import java.util.List;

/**
 * @author ravi
 *
 */
@UrlBinding(MyProfileAction.URL)
public class MyProfileAction extends BaseDashboardAction{
	
	public static final String URL = "/my-profile.action";
	
	private static final String PUBLIC_PROFILE_PAGE = JSP_ROOT + "/public-profile.jsp";
	private static final String DASHBOARD_CONTENT = JSP_ROOT + "/my-profile.jsp";
	private static final String DASHBOARD_CONTENT_THANK = JSP_ROOT + "/thank-you.jsp";
	private static final String HEADER_INCLUDE = JSP_ROOT + "/my-profile-include.jsp";

	
//	private final UserManager userManager;
//	private final IAdministrationDao administrationDao;
	
//	private RateService rateService = RateServiceImpl.getInstance();

    private boolean showPreview = false;

//    private List<ISelection> rptgSchools;
//    private List<ISelection> specialities;
//    private List<ISelection> expertises;
//    private List<ISelection> hobbies;
//    private List<ISelection> jobTypes;
//    private List<ISelection> computerOses;
//    private List<ITimeZone> timeZones;
    private String dashboardContent = DASHBOARD_CONTENT;
    private DashboardTab currentTab = null; //DashboardTab.PROFILE;
    private String selectionItemType;
//    private List<RateContact> arateContactList;
	/**
	 * 
	 */
	public MyProfileAction() {
//		userManager = UserManager.getInstance();
//        administrationDao = AdministrationDaoFactory.getAdministrationDao();
	}

	
	/* (non-Javadoc)
	 * @see com.depo.quiggle.view.controller.BaseDashboardAction#getDashboardContent()
	 */
	@Override
	public String getDashboardContent() {
		return dashboardContent;
	}


	/* (non-Javadoc)
	 * @see com.depo.quiggle.view.controller.BaseDashboardAction#getHeaderInclude()
	 */
	@Override
	public String getHeaderInclude() {
		return HEADER_INCLUDE;
	}

	
//	private UserProfileVo userProfile;
//	public UserProfileVo getUserProfile(){
//		if(userProfile == null){
//			userProfile = userManager.getUserPrivateProfile(getAuthUserId());
//		}
		
		//To manage deleted selection items
//		if(this.selectionItemType != null && this.selectionItemType.equalsIgnoreCase("true")){

//			for(SelectionType selectionType : SelectionType.values()){
//				userProfile.getUserProfile().setUserSelection(selectionType, null);
//			}
//			this.selectionItemType = "false";
//		}
//		return userProfile;
//	}

    /*public Resolution cancel(){
        return new RedirectResolution(QglLogPendingAction.URL);
    }*/

    public Resolution save(){
				
//		userManager.updateProfile(getUserProfile());
		
		return new RedirectResolution(MyProfileAction.URL).addParameter("savedMessage", "true");
		
//		return processPage();
	}
	
	 public Resolution saveAndNextAction(){
		
//		userManager.updateProfile(getUserProfile());
		
		String nextAction = getContext().getRequest().getParameter("nextAction");
		return new RedirectResolution(nextAction);
		
//		return processPage();
	}
	 
    public Resolution preview(){
    	
    	String changeInd = getContext().getRequest().getParameter("changeInd");
        this.showPreview = true; 

        if(changeInd.equalsIgnoreCase("true"))
         return new ForwardResolution("/WEB-INF/jsp/include/base-html.jsp").addParameter("msg","notnull");
        else
        	return showPage();
       
    }
	
//	public List<IContactType> getContactTypes(){
//		return userManager.getContactTypes();
//		return ContactType.values();
//	}
	
//	public List<ILocationType> getLocationTypes(){
//		return userManager.getLocationTypes();
//	}
	
//	public List<ICertificateType> getCertificateTypes(){
//        return userManager.getCertificateTypes();
//	}

	// to retrieve all certificate category types
//	public List<ICertifCategType> getCertifCategTypes(){
//        return userManager.getCertifCategTypes();
//	}

//	public List<IEmergencyContactType> getEmergencyContactTypes(){
//		return userManager.getEmergencyContactTypes();
//	}
	
//	public List<ISelection> getRptgSchools(){
//        if(rptgSchools == null){
//		    rptgSchools = administrationDao.getSelections(SelectionType.RPTG_SCHOOL);
//        }
//        return rptgSchools;
//	}


//    public List<ISelection> getSpecialities(){
//        if(specialities == null){
//            specialities = administrationDao.getSelections(SelectionType.SPECIALITY);
//        }
//        return specialities;
//    }


//    public List<ISelection> getExpertises(){
//        if(expertises == null){
//            expertises = administrationDao.getSelections(SelectionType.EXPERTISE);
//        }
//        return expertises;
//    }

//    public List<ISelection> getHobbies(){
//        if(hobbies == null){
//            hobbies = administrationDao.getSelections(SelectionType.HOBBY);
//        }
//        return hobbies;
//    }

//    private List<ISelection> catSoftwares;
//    public List<ISelection> getCatSoftwares(){
//        if(catSoftwares == null){
//            catSoftwares = administrationDao.getSelections(SelectionType.CAT_SOFTWARE);
//        }
//        return catSoftwares;
//    }

//    public List<ISelection> getComputerOses(){
//        if(computerOses == null){
//            computerOses = administrationDao.getSelections(SelectionType.COMPUTER_OS);
//        }
//        return computerOses;
//    }

//    public List<ISelection> getJobTypes(){
//        if(jobTypes == null){
//            jobTypes = administrationDao.getSelections(SelectionType.JOB_TYPE);
//        }
//        return jobTypes;
//    }

//    public UsaStates[] getUsaStates(){
//        return UsaStates.values();
//    }

    public boolean isShowPreview() {
        return showPreview;
    }

    public String getPublicProfilePage(){
        return PUBLIC_PROFILE_PAGE;
    }

    @Override
    public DashboardTab getCurrentTab() {
        return currentTab;
    }
    
//    public HourTypes[] getHourTypes(){
//    	return HourTypes.values();
//    }

	// to retrieve all certificate category values
//    private List<IUserProfile> category;
	
//	public List<IUserProfile> getCategory() {
//		if(category == null){
//			category = userManager.getUserCertificationCategoryValues(getAuthUserId());
//        }
//		return category;
//	}


	public String getSelectionItemType() {
		return selectionItemType;
	}


	public void setSelectionItemType(String selectionItemType) {
		this.selectionItemType = selectionItemType;
	}


//	public List<ITimeZone> getTimeZones() {
//	 if(timeZones == null)
//		timeZones =  userManager.getAllTimeZone();
//
//		return timeZones;
//	}
	
	public Resolution saveFeedBackDetails(){
		 String jsonResult="";
		 try{
			 String jObj = getContext().getRequest().getParameter("feedBackDetails");
//			net.sf.json.JSONObject feedBackString = (JSONObject) net.sf.json.JSONSerializer.toJSON(jObj);
			
			
			
//			int feedbackType = feedBackString.getInt("feedbackType");
//			int easeOfUse = feedBackString.getInt("easeOfUse");
//			int lookAndFell = feedBackString.getInt("lookAndFell");
//			int popup =  feedBackString.getInt("popup");
//			int help = feedBackString.getInt("help");
//			int tooltip = feedBackString.getInt("tooltip");
//			String comment = feedBackString.getString("comment");
			
//			FeedBackVO feedBackVo = new FeedBackVO();
			
//			feedBackVo.setFeedbackType(feedbackType);
//			feedBackVo.setEaseOfUse(easeOfUse);
//			feedBackVo.setLookAndFell(lookAndFell);
//			feedBackVo.setPopup(popup);
//			feedBackVo.setHelp(help);
//			feedBackVo.setTooltip(tooltip);
//			feedBackVo.setComment(comment);
//			feedBackVo.setCreatedBy(getAuthUserId());
//			feedBackVo.setCreatedDate(new Date());
			
//			userManager.saveFeedBackDetails(feedBackVo);
		
				
				
//		jsonResult = new JSONSerializer().serialize("success");
				
		 }
		 catch(Exception e){
			e.printStackTrace(); 
		 }
		return new StreamingResolution("application/javascript", jsonResult);
	 }
	 
	public Resolution getAccountreceivableProfilesDetails()
	{
		String jsonResult="";
		try{
//		arateContactList = rateService.getAccountReceivableContactDetails((long) getAuthUserId());
//		 jsonResult = new JSONSerializer().serialize(arateContactList);
		}catch (Exception e) {
			e.printStackTrace();
		}
		 
		return new StreamingResolution("application/javascript",jsonResult);
	}


}